import 'package:example/pages/button_demo_page.dart';
import 'package:example/viewmodel/second_viewmodel.dart';
import 'package:flutter/material.dart';
import 'package:flutter_scaffold/flutter_scaffold.dart';

class ViewModel2DemoPage extends StatefulWidget {
  const ViewModel2DemoPage({super.key});

  @override
  _Second2PageState createState() => _Second2PageState();
}

class _Second2PageState extends ViewModelWidgetState<SecondViewModel,ViewModel2DemoPage>{
  @override
  void initState() {
    super.initState();
    print("ViewModel2DemoPage");
    Future.delayed(Duration(seconds: 2),(){
      viewModel.title.value="sdfdsffsf";
    });
  }

  @override
  Widget buildWidget(BuildContext context, SecondViewModel viewModel) {
    return Scaffold(
      appBar: AppBar(title: Text("data")),
      body: Obx(
        () => StatusWidget(
          type: viewModel.status.value,
          body: Column(
            children: [
              Text(viewModel.leght.value ? "nihao" : "cuowu"),
              Text(viewModel.title.value),
            ],
          ),
          loading: Text("加载中...等稍等"),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          viewModel.title.value = "文本变化了";
          Get.to(ButtonDemoPage());
        },
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }

  @override
  SecondViewModel createViewModel() {
    return SecondViewModel();
  }

  @override
  String? viewModelTag() {
    return "232";
  }

  @override
  void onReady() {
  }
}
